﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>选择量订预收单</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <style>
    body{padding:10px; font-size:14px; background:#fff; width:95%; margin:0 auto; font-size:14px; line-height:20px; overflow:scroll;}
    p{margin-bottom:10px;}
    input{border:1px solid #999; padding:5px 10px; margin:0 10px 10px 0;}
  </style>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">量定单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="lddocno" id="lddocno" placeholder="请输入量定单号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">店仓名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="dcname" id="dcname" placeholder="请输入店仓名称" autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>

        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-lg5">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <table class="layui-hide" id="List_ysd" lay-filter="test-table-onrow"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-lg5">
                <div class="layui-card">
                    <div class="layui-btn-group test-table-operate-btn" style="display:none;">
                        <input id="uidsub" class="form-control" name="uid" type="hidden" value="">
                        <button class="layui-btn" id="saveBtn" data-type="getCheckData"></button>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="List_kh"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../../layuiadmin/js/jquery.min2.1.4.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script src="../../layuiadmin/js/cookie.js"></script>

    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'useradmin', 'table', 'laypage'], function () {
            var $ = layui.$
                , form = layui.form
                , table = layui.table
                , laypage = layui.laypage;
            table.render({
                elem: '#List_ysd'
                , id: 'ysd_table'//容器的ID
                , url: 'ashx/list.ashx?type=getlist_ysd&userid=' + $.cookie("id")
                , toolbar: '#test-table-radio-toolbarDemo'
                , method: 'POST'
                , page: true
                , limits: [10, 20, 30]
                , limit: 10
                , cols: [[
                    { type: 'radio' }
                    //, { field: 'id',title: 'id', align: 'center', }
                    , { field: 'docno', width: 160, title: '单据号', align: 'center', sort: true }
                    , { field: 'billdate', width: 100, title: '日期', align: 'center', sort: true }
                    , { field: 'name', width: 190, title: '店铺名称', align: 'center' }
                    //, { field: 'ld_flag', width: 180, title: 'ld_flag', align: 'center' }

                ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
                , where: {
                    lddocno: $('#lddocno').val(),
                    dcname: $('#dcname').val()
                }
            });
            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(test-table-onrow)', function (obj) {
                var data = obj.data;
                table.render({
                    elem: '#List_kh'
                    , url: 'ashx/list.ashx?type=getlist_kh&ysdid=' + data.id
                    , toolbar: '#test-table-radio-toolbarDemo'
                    , method: 'POST'
                    , page: true
                    , limits: [10, 20, 30]
                    , limit: 10
                    , cols: [[
                        { type: 'checkbox' }
                        , { field: 'xiaolei', width: 120, title: '品名', align: 'center' }
                        , { field: 'name', width: 130, title: '款号', align: 'center' }
                        , { field: 'value1', width: 100, title: '颜色', align: 'center' }
                        , { field: 'value2', width: 100, title: '尺码', align: 'center' }
                        , { field: 'qty', width: 80, title: '数量', align: 'center' }
                        //, { field: 'pricelist', width: 80, title: '标准价', align: 'center' }
                        //, { field: 'priceactual', width: 80, title: '成交价', align: 'center' }
                        //, { field: 'tot_amt_actual', width: 80, title: '成交金额', align: 'center' }
                    ]], parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.count, //解析数据长度
                            "data": res.data //解析数据列表
                        };
                    }
                });
                //标注选中样式
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                //选中radio样式
                obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
            });
            /*点击确定*/
            $("#saveBtn").on('click', function () {
                var checkStatus = table.checkStatus('List_kh');
                if (!checkStatus.data.length) { //判断，如果没有选择提示
                    layer.msg('请选择数据', { icon: 7 }); return;
                }
                else if (checkStatus.data.length > 1) {
                    layer.msg('目前只能支持一个款号', { icon: 7 }); return;
                }
                else {//否则，序列化为Json字符串，存放在视图页面中
                    $("#uidsub").val(JSON.stringify(checkStatus.data));
                    //关闭层
                    if ($("#uidsub").val() != null || $("#uidsub").val() != '') {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                }
            });
            //监听排序
            table.on('sort(List_ysd)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                table.reload('ysd_table', {//刷新列表
                    initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                    , where: { //请求参数
                        field: obj.field //排序字段
                        , order: obj.type //排序方式
                        , lddocno: $('#lddocno').val()
                        , dcname: $('#dcname').val()
                    }
                });
            });
            //监听搜索
            form.on('submit(LAY-user-front-search)', function (data) {
                var field = data.field;
                //执行重载
                table.reload('ysd_table', {
                    where: {
                        lddocno: field.lddocno,
                        dcname: field.dcname
                    }, page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
            //头工具栏事件
            table.on('toolbar(test-table-radio)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                switch (obj.event) {
                    case 'getCheckData':
                        var data = checkStatus.data;  //获取选中行数据
                        layer.alert(JSON.stringify(data));
                        break;
                };
            });
        });
    </script>
</body>
</html>
